package MainController;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;

/**
 * Servlet implementation class FirstAction
 */
public class FirstAction extends HttpServlet  implements javax.servlet.Servlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FirstAction() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String RequestURI=request.getRequestURI();
		String contextPath=request.getContextPath();
		String command=RequestURI.substring(contextPath.length());
		ActionForward forward=null;
		request.setCharacterEncoding("UTF-8");
		
		if(command.equals("/firstmain.ma")){
			forward=new ActionForward();
			forward.setRedirect(false);
			request.setAttribute("bord", "0");
			forward.setPath("./main/FirstMain.jsp");
		}
		else if(command.equals("/youngmain.ma")){
			forward=new ActionForward();
			forward.setRedirect(false);
			System.out.println("시작2");
			
			request.setAttribute("bord", "1");
			forward.setPath("./main/YoungMain.jsp");
			System.out.println("시작3");
		}
		else if(command.equals("/oldmain.ma")){
			forward=new ActionForward();
			forward.setRedirect(false);
			System.out.println("시작2");
			
			request.setAttribute("bord", "2");
			forward.setPath("./main/OldMain.jsp");
			System.out.println("시작3");
		}
		if(forward.isRedirect()){
			response.sendRedirect(forward.getPath());
		}else{
			RequestDispatcher dispatcher=
				request.getRequestDispatcher(forward.getPath());
			dispatcher.forward(request, response);
		}
		
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

}
